<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

include 'mcrypt.php';
header("Content-type: text/html; charset=UTF-8");
$action = $_GET["action"];
switch ($action){
    case "encrypt":
        $data = trim($_POST["data"]);
        $key = trim($_POST["key"]);
        $cipher = trim($_POST["cipher"]);
        $mode = trim($_POST["mode"]);
        if($data==null){
            echo '请输入明文!';
        }elseif ($key==null) {
            echo '请输入密钥';
        }elseif ($cipher==null) {
            echo '请选择cipher';
        }elseif ($mode==null) {
            echo '请选择mode';
        }else {
            $mcry=new mcrypt();
            $encrypt1 = $mcry->encrypt($data,$key,$cipher,$mode);
            echo "加密成功！密文为：".$encrypt1;
        }       
        break;
    case "decrypt":
        $decrypt = trim($_POST['decrypt']);       
        $key = trim($_POST['key']);    
        $cipher = trim($_POST['cipher']);
        $mode = trim($_POST['mode']);
        if($decrypt==null){
            echo '请输入密文!';
        }elseif ($key==null) {
            echo '请输入密钥';
        }elseif ($cipher==null) {
            echo '请选择cipher';
        }elseif ($mode==null) {
            echo '请选择mode';
        }else {
            $mcry=new mcrypt();
            $decrypt1 = $mcry->decrypt($decrypt,$key,$cipher, $mode);
            echo "解密成功！明文为：".$decrypt1;
        }       
        break;
}
    
    
    
